package com.example.rbacmanage.controller.system;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.system.DictData;
import com.example.rbacmanage.service.system.DictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/dictdata")
public class DictDataController {
    @Autowired
    private DictDataService dictDataService;

    @GetMapping("/page")
    public Result page(DictData dictData){
        return Result.success(dictDataService.getPage(dictData));
    }

    @GetMapping("/{id}")
    public Result info(@PathVariable Long id){
        return Result.success(dictDataService.getById(id));
    }

    @PreAuthorize("hasAnyAuthority('system:dictdata:add')")
    @PostMapping("/add")
    public Result add(@RequestBody DictData dictData){
        dictDataService.save(dictData);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('system:dictdata:update')")
    @PutMapping("/update")
    public Result update(@RequestBody DictData dictData){
        dictDataService.update(dictData);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('system:dictdata:remove')")
    @DeleteMapping("/remove")
    public Result remove(@RequestBody Long[] ids){
        dictDataService.remove(ids);
        return Result.success();
    }
}
